package com.yict.csms.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yict.common.service.impl.CommonService;
import com.yict.csms.system.dao.impl.TreeNodeDaoImpl;
import com.yict.csms.system.entity.TreeNode;
import com.yict.csms.system.entity.UserGroup;
import com.yict.csms.system.service.ITreeNodeService;

/**
 * 
 * 
 * @author ryan.wang
 * 
 */
@Service
public class TreeNodeServiceImpl extends CommonService<TreeNode, Long> implements
		ITreeNodeService {
	@Autowired
	private TreeNodeDaoImpl treeNodedaoimpl;

	public List<TreeNode> getMenu(List<UserGroup> userGroups, boolean inOrNotIn) {
		StringBuilder queryString = new StringBuilder();
		Map<String, Object> map = new HashMap<String, Object>();
		String field = " order by c.nodeId asc";
		queryString.append("from TreeNode as c where 1=1");
		if(inOrNotIn) {
			queryString.append(" and c.nodeId in (select t.treeNode.nodeId from UserGroupTreeNode t where t.userGroup in (:userGroups))");
			map.put("userGroups", userGroups);
		}
		queryString.append(field);
		List<TreeNode> list = treeNodedaoimpl.search(queryString.toString(), map, null);
		return list;
	}
}
;